<{include file="../common/header.tpl"}>
<link href="/css/uploadify.css" rel="stylesheet">
<script type="text/javascript">
function AutoResizeImage(maxWidth,maxHeight,objImg){
    var img = new Image();
    img.src = objImg.src;
    var hRatio;
    var wRatio;
    var Ratio = 1;
    var w = img.width;
    var h = img.height;
    wRatio = maxWidth / w;
    hRatio = maxHeight / h;
    if (maxWidth ==0 && maxHeight==0){
        Ratio = 1;
    }else if (maxWidth==0){
        if (hRatio<1) Ratio = hRatio;
    }else if (maxHeight==0){
    if (wRatio<1) Ratio = wRatio;
    }else if (wRatio<1 || hRatio<1){
        Ratio = (wRatio<=hRatio?wRatio:hRatio);
    }
    if (Ratio<1){
        w = w * Ratio;
        h = h * Ratio;
    }
        objImg.height = h;
        objImg.width = w;
}
</script>
<table width="100%" border="0" cellspacing="0">
    <tr>
          <td width="13%" valign="top">
                <{include file="../common/left.tpl"}>
          </td>
          <td width="87%" valign="top">

                  <table width="100%" border="0" cellspacing="0">
                    <tr>
                    <td>
                      <div class="subnav">
                        <div class="content-menu ib-a blue line-x"> 

                              <a href="/webadmin/network/bank"><em>银行管理</em></a><span>|</span>
                              <a href="/webadmin/network/addbank" class="on"><em>添加银行</em></a>
                         <div class="clearbox"></div>
                        </div>
                      </div>

                      <div class="pad_10">
                        <div class="common-form">
                            <form action="/webadmin/network/<{if $info}>doeditbank<{else}>doaddbank<{/if}>" method="post" name="myform" id="myform">
                              <table width="100%" class="table_form">
                              <tbody>
                                <tr>
                                  <td>银行名称</td>
                                  <td><input type="text" name="bank_name" class="input-text" id="bank_name" value="<{$info.bank_name}>"></td>
                            </tr>
                              <tr>
                              <td>银行域名</td> 
                              <td><input type="text" name="domain" maxlength="8" class="input-text" id="domain" value="<{$info.domain|strtoupper}>"><span style="color: red;">限制为最大8个字符（英文和数字）如ICBCBJ、ICBCTJ</span></td>
                              </tr>
                              <tr>
                              <td width="80">银行登陆背景</td> 
                              <td><label>
                                <input type="file" name="uploadify" id="uploadify" />
                              </label>
                                  <input type="hidden" name="background" id="cover" value="<{$info.background}>">
                                  <div id="cases_img"><{if $info.background}><img src="<{$info.background}>" onload="AutoResizeImage(340,0,this)" class="img-responsive">&nbsp;&nbsp;<a href="javascript:;" onclick="del_background(<{$info.bank_id}>);">删除</a><{/if}></div>
                              </td>
                              </tr>
                              <tr>
                              <td width="80">银行LOGO</td> 
                              <td><label>
                                <input type="file" name="uploadify_logo" id="uploadify_logo" />
                              </label>
                                  <input type="hidden" name="logo" id="logo" value="<{$info.logo}>">
                                  <div id="logo_img"><{if $info.logo}><img src="<{$info.logo}>" onload="AutoResizeImage(250,0,this)" class="img-responsive">&nbsp;&nbsp;<a href="javascript:;" onclick="del_logo(<{$info.bank_id}>);">删除</a><{/if}></div>
                              </td>
                              </tr>
                              </tbody>
                              </table>
                              <div class="bk15"></div>
                              <input type="hidden" name="bank_id" value="<{$info.bank_id}>">
                              <input type="submit" class="button" value="提交" name="dosubmit">
                             </form>
                        </div>
                      </div>
                    </td>
                    </tr>
                  </table>

          </td>
    </tr>
</table>
<{include file="../common/footer.tpl"}>
<script src="/js/jquery.uploadify.min.js"></script>
<script type="text/javascript">
   $('#myform').submit(function(){
       var domain = $('#domain').val();
       var bank_name = $('#bank_name').val();
       if (bank_name == '') {
           alert('银行名称不能为空');return false;
        }
        var pattern = /^[A-Za-z0-9]+$/;
        if (!pattern.test(domain)) {
            alert('只能为英文字符或数字');
            return false;
        }
        return true;
   });
    $('#uploadify').uploadify({
        //'debug': true,
        'buttonText' : '选择文件',
        'fileObjName' : 'upfile',   
        'swf'      : '/js/uploadify.swf',
        'fileTypeExts' : '*.gif; *.jpg; *.png',
        'uploader' : '/webadmin/attach/do?attach_type=bank',
        'onUploadSuccess' : function(file, data, response) {
            var obj = eval('(' + data + ')');
            if (obj.state =='SUCCESS'){
                $('#cover').val(obj.url);
                $('#cases_img').html('<img src="'+obj.url+'" class="img-responsive">');
                alert('上传成功');
            } else {
                alert('上传失败');
            }
        } 
    });
        $('#uploadify_logo').uploadify({
        //'debug': true,
        'buttonText' : '选择文件',
        'fileObjName' : 'upfile',   
        'swf'      : '/js/uploadify.swf',
        'fileTypeExts' : '*.gif; *.jpg; *.png',
        'uploader' : '/webadmin/attach/do?attach_type=bank',
        'onUploadSuccess' : function(file, data, response) {
            var obj = eval('(' + data + ')');
            if (obj.state =='SUCCESS'){
                $('#logo').val(obj.url);
                $('#logo_img').html('<img src="'+obj.url+'" class="img-responsive">');
                alert('上传成功');
            } else {
                alert('上传失败');
            }
        } 
    });
    function del_logo(bank_id){
        if (confirm('确定删除LOGO图片？')) {
            $.getJSON('/webadmin/network/dellogo',{bank_id:bank_id,type:'logo'},function(res){
                if (res.status==1) {
                    $('#logo').val('');
                    $('#logo_img').remove();
                }
                alert(res.note);
            });
        }
    }
    function del_background(bank_id){
        if (confirm('确定删除背景图片？')) {
            $.getJSON('/webadmin/network/dellogo',{bank_id:bank_id,type:'background'},function(res){
                if (res.status==1) {
                    $('#cover').val('');
                    $('#cases_img').remove();
                }
                alert(res.note);
            });
        }
    }
</script>
